/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jebert.javamessage.control;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import org.jebert.javamessage.model.Contact;

/**
 *
 * @author jebert
 */
public class MessageDiscover extends Thread {

    Contact mdcontact;

    public MessageDiscover() {

    }

    public void run() {
        try {

            DatagramPacket dgram = new DatagramPacket(new byte[25], 25);
            MulticastSocket socket = new MulticastSocket(7077);
            socket.joinGroup(InetAddress.getByName("235.1.1.1"));

            while (true) {

                socket.receive(dgram);

                String cname = new String(dgram.getData(), 0, dgram.getLength());

              //  Contact cnt = new Contact(dgram.getAddress(), dgram.getPort(), System.currentTimeMillis(), cname, translator);


                Thread.sleep(1000);
            }

        } catch (InterruptedException ex) {
            Logger.getLogger(ContactDiscover.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ContactDiscover.class.getName()).log(Level.SEVERE, null, ex);
        }


    }
}
//        Contact c = new Contact();
//        c.setHost(host);
//        c.setPort(port);
//        c.setLastCheckIn(System.currentTimeMillis());
//
//        int idx = modelo.indexOf(c);
//        if ( idx>=0) {
//            updateContact(idx);
//        } else {
//            modelo.addElement(c);
//        }
//
//        listaContactos.repaint();